<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.8.3.js" type="text/javascript"></script>
    <script>
        $(function () {
            $("#name").blur(function () {
                $.get("SearchUserByNameServlet",{  name:$("#name").val()},
                    function (data) {
                    if(data=="true"){
                        $("#msg").html("用户名已经存在").css("color","red");
                        $("#sub").attr("disabled","disabled");
                    }else{
                        $("#msg").html("可以使用").css("color","green");
                        $("#sub").attr("disabled",false);
                    }
                    }
                )
            })
        })
    </script>
</head>
<body>
<form>
    用户名：<input type="text" id="name" name="name"><span id="msg"></span><br>
    <input type="submit" id="sub" value="注册">
</form>

</body>
</html>